import { defineStore, storeToRefs } from 'pinia'
import { useEleSelectStore } from './eleSelect'
import type { Map, Position } from '.'

export const useMapEditStore = defineStore('mapEdit', () => {
  const isDraging = ref(false)
  const { currentEle } = storeToRefs(useEleSelectStore())

  const map = reactive<Map>([
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],

  ])
  function setElement(pos: Position) {
    if (currentEle.value === 0)
      return
    map[pos.y][pos.x] = currentEle.value
  }
  function setNewMap(newMap: Map) {
    map.splice(0, map.length, ...JSON.parse(JSON.stringify(newMap)))
  }
  return { map, setNewMap, setElement, isDraging }
})
